home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / COMM / INTERNET / TELNET / RLOGIND / !RloginD / telnet / term_h < prev   
Text File  |  1993-09-02  |  4KB  |  162 lines

  1. /* > term.h
  2.  * (C) 1992 Andrew Brooks
  3.  * arb@comp.lancs.ac.uk
  4.  * 1.00 Fri Feb  5 11:51:16 GMT 1993
  5.  *      First incarnation
  6.  */
  7.  
  8. /*
  9.  * System-independent terminal handling library.
  10.  * When compiling this library the appropriate flags must be set:
  11.  * TERMIO
  12.  *   This is typically on System III and System V (and SunOS)
  13.  *   Look for a termio.h header file and termio manual page
  14.  *   #define TERMIO
  15.  * SGTTY
  16.  *   This is typically on Version 7 systems
  17.  *   Look for a sgtty.h header file
  18.  *   #define SGTTY
  19.  * ITTY
  20.  *   This is typically on BSD systems
  21.  *   Look for a ioctl.h header file and a tty(4) manual page
  22.  *   #define ITTY
  23.  * If more than one of the above applies (eg.SunOS) then use TERMIO
  24.  * If none of the above apply then you are stuck.
  25.  */
  26.  
  27. #ifndef __term_h
  28. #define __term_h
  29.  
  30. #include "cproto.h"
  31.  
  32. /* Simple error check */
  33.  
  34. #ifndef TERMIO
  35. #ifndef SGTTY
  36. #ifndef ITTY
  37. /* Have a good try at guessing */
  38. /* Try Sequent DynixPTX */
  39. #ifdef _SEQUENT_
  40. #define TERMIO
  41. #endif /* _SEQUENT_ */
  42. /* Try Sequent Dynix */
  43. #ifdef sequent
  44. #define ITTY
  45. #endif /* sequent */
  46. /* Try Sun (assume SunOS 4) */
  47. #ifdef sun
  48. #define TERMIO
  49. /* Sun can use both termio and termios.  Prefer termio for compatibility */
  50. #endif /* sun */
  51. #endif
  52. #endif
  53. #endif
  54.  
  55. /* See if all those failed */
  56. #ifndef TERMIO
  57. #ifndef SGTTY
  58. #ifndef ITTY
  59. error One of TERMIO, SGTTY or ITTY must be defined (see term.h)
  60. #endif
  61. #endif
  62. #endif
  63.  
  64. /* First include the correct header file */
  65.  
  66. #ifdef TERMIO
  67. /* On some termio systems this would be <sys/termio.h> */
  68. /* SunOS would be one example but luckily it has symbolic links so no need */
  69. #include <termio.h>
  70. #endif
  71.  
  72. #ifdef SGTTY
  73. #include <sgtty.h>
  74. #endif
  75.  
  76. #ifdef ITTY
  77. /* This may be <ioctl.h> or <sys/ioctl.h> ? */
  78. #include <sys/ioctl.h>
  79. /* All this junk is needed because these system are a big hack */
  80. struct itty
  81. {
  82.     struct sgttyb  sgttyb;
  83.     struct tchars  tchars;
  84.     struct ltchars ltchars;
  85.     long           lmode;
  86. };
  87. #endif
  88.  
  89. #include <fcntl.h>               /* for open(2) modes */
  90.  
  91.  
  92. #define TERM_MIN 4              /* minimum characters to satisfy read() */
  93. #define TERM_TIME 5             /* intercharacter delay for read() */
  94.  
  95. #define BUFSIZE 1024            /* used for Term_CopyStuff */
  96.  
  97.  
  98. /* Common structures and ioctls */
  99. #ifdef TERMIO
  100. #define TERM_STRUCT struct termio
  101. #define TERM_GET TCGETA
  102. #define TERM_SET TCSETA
  103. /* TCSETAW may be used to wait for all pending output characters to be sent
  104.  * first, useful when altering output modes.  TCSETAF may be used to flush
  105.  * the input queue first, useful when typeahead may not be desirable.
  106.  */
  107. /* Be careful, SETS is for termios, SETA is for termio */
  108. #endif
  109. #ifdef SGTTY
  110. #define TERM_STRUCT struct sgttyb
  111. #define TERM_GET TIOCGETP
  112. #define TERM_SET TIOCSETP
  113. #endif
  114. #ifdef ITTY
  115. #define TERM_STRUCT struct itty
  116. #define TERM_GET TIOCGETP            /* not used */
  117. #define TERM_SET TIOCSETP            /* not used */
  118. #endif
  119.  
  120. /* On some systems O_NDELAY and FNDELAY are equivalent */
  121. #ifdef SGTTY
  122. #define TERM_SETNONBLOCKING O_NDELAY
  123. #define TERM_WOULDBLOCK EAGAIN
  124. #endif
  125. #ifdef TERMIO
  126. #define TERM_SETNONBLOCKING O_NDELAY
  127. #define TERM_WOULDBLOCK EAGAIN
  128. #endif
  129. #ifdef ITTY
  130. #define TERM_SETNONBLOCKING FNDELAY
  131. #define TERM_WOULDBLOCK EWOULDBLOCK
  132. #endif
  133.  
  134.  
  135. /* Now declare the public term_ functions */
  136.  
  137.  
  138. /*
  139.  * Save and restore the full status of the terminal associated with the
  140.  * file descriptor.  Includes such items as raw, echo, mappings etc.
  141.  * Declare a TERM_STRUCT and pass a pointer to it for filling in.
  142.  */
  143. extern int Term_Save P_((int fd, TERM_STRUCT *bug));
  144. extern int Term_Restore P_((int fd, TERM_STRUCT *buf));
  145.  
  146.  
  147. /*
  148.  * Set the file descriptor to be raw (not cooked) I/O.
  149.  * Note that restoring NonRaw puts the fd back in full non-raw mode,
  150.  * cbreak is never used.
  151.  */
  152. extern int Term_Raw P_((int fd));
  153. extern int Term_NonRaw P_((int fd));
  154.  
  155. /*
  156.  * Turn off echoing only
  157.  */
  158. extern int Term_NoEcho P_((int fd));
  159.  
  160.  
  161. #endif /* __term_h */
  162.